<?php
/**
 * Created by PhpStorm.
 * Script Name: Minicategory.php
 * Create: 2022/11/16 18:01
 * Description: 类目管理
 * Author: fudaoji<fdj@kuryun.cn>
 */

namespace plugin\wechat\app\tenant\controller;

use EasyOpen\Tencent\Request\Mp\WxOpenDeleteCategory;
use plugin\wechat\app\TenantController;
use plugin\wechat\app\service\MiniCategory as CategoryService;

class Minicategory extends TenantController
{

    public function __construct()
    {
        parent::__construct();
    }


    /**
     * 类目列表
     * @return mixed|\support\Response
     * @throws \EasyWeChat\Kernel\Exceptions\HttpException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
     * @throws \Psr\SimpleCache\InvalidArgumentException
     * Author: fudaoji<fdj@kuryun.cn>
     */
    public function index(){
        if(is_string($response = CategoryService::categoryGet())){
            return $this->error($response);
        }

        $list = $response;
        $assign['data_list'] = $list;
        $assign['audit_status'] = CategoryService::auditStatus();
        return $this->show($assign);
    }

    /**
     * 删除类目
     * @return \support\Response
     * @throws \EasyWeChat\Kernel\Exceptions\HttpException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
     * @throws \Psr\SimpleCache\InvalidArgumentException
     * Author: fudaoji<fdj@kuryun.cn>
     */
    public function delPost(){
        if(request()->isPost()){
            $post_data = input('post.');
            if(empty($post_data['first']) || empty($post_data['second'])){
                return $this->error('参数错误');
            }
            if(is_string($response = CategoryService::categoryDel($post_data))){
                return $this->error($response);
            }
            return $this->success('操作成功!');
        }
    }
}